package com.xuzhen.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xuzhen.dao.UserDao;
import com.xuzhen.domain.User;
import com.xuzhen.service.UserService;
import com.xuzhen.util.EncryptUtil;

@Service("userService")
@Transactional
public class UserServiceImpl implements UserService {

	@Autowired
	private UserDao userDao;

	@Override
	public int countAll() {
		return userDao.countAll();
	}

	@Override
	public int countUserByName(String userName) {
		return userDao.countUserByName(userName);
	}

	@Override
	public int delete(String userName) {
		return userDao.delete(userName);
	}

	@Override
	public User findByUserName(String userName) {
		return userDao.findByUserName(userName);
	}

	@Override
	public User insert(User user) {
		user.setPassword(EncryptUtil.md5Encrypt(user.getPassword()));
		userDao.insert(user);
		return userDao.getById(user.getId());
	}

	@Override
	public List<User> selectAll() {
		return userDao.selectAll();
	}

	@Override
	public User update(User user) {
		userDao.update(user);
		return userDao.getById(user.getId());
	}

}
